/**
 * 
 */
package com.zufangbao.earth.handler.impl;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;

import com.zufangbao.earth.handler.SignatureHandler;
import com.zufangbao.gluon.opensdk.SignatureUtilsForPartner;
import com.zufangbao.gluon.spec.quark.GlobalSpec4Quark;
import com.zufangbao.gluon.spec.quark.PaymentSpec;

/**
 * @author lute
 *
 */

@Component("signatureHandler")
public class SignatureHandlerImpl implements SignatureHandler {
	
	public boolean checkAppSignature(String appId, String appSecret, String signature, String customerId) {
		
		Map<String,Object> paramsMap = new HashMap<String,Object>();
		
		paramsMap.put(GlobalSpec4Quark.PARAM_APP_ID, appId);
		paramsMap.put(GlobalSpec4Quark.PARAM_APP_SECRET, appSecret);
		paramsMap.put(PaymentSpec.PaymentParam.PARAM_CUSTOMER_ID, customerId);
		
		return StringUtils.equals(signature, SignatureUtilsForPartner.makeMD5Signature(paramsMap));
	}

	@Override
	public boolean checkAppSignature4Term(String appId, String appSecret,
			String signature, String... parameters) {
		
		Map<String,Object> paramsMap = new HashMap<String,Object>();
		
		paramsMap.put(GlobalSpec4Quark.PARAM_APP_ID, appId);
		paramsMap.put(GlobalSpec4Quark.PARAM_APP_SECRET, appSecret);
		paramsMap.put(GlobalSpec4Quark.PARAM_ORDER_NO, SignatureUtilsForPartner.encodeValue(parameters[0]));
		
		return signature.equals(SignatureUtilsForPartner.makeMD5Signature(paramsMap));
	}
	
}
